package org.fcs.framework.generator;


/**
 * Created by Administrator on 2016/2/23.
 */
public class Tools {
      /**
     * 把以_分隔的列明转化为字段名
     *
     * @param columnName 列名
     * @return String 字段名
     */
    public static String getFieldName(String columnName) {
        if (columnName == null) {
            return "";
        }

        StringBuffer fieldNameBuffer = new StringBuffer();

        boolean nextUpperCase = false;
        columnName = columnName.toLowerCase();
        for (int i = 0; i < columnName.length(); i++) {
            char c = columnName.charAt(i);

            if (nextUpperCase) {
                fieldNameBuffer.append(columnName.substring(i, i + 1).toUpperCase());
            } else {
                fieldNameBuffer.append(c);
            }

            if (c == '_') {
                nextUpperCase = true;
            } else {
                nextUpperCase = false;
            }
        }

        String fieldName = fieldNameBuffer.toString();
        fieldName = fieldName.replaceAll("_", "");
        return fieldName;
    }

    /**
     * 字符串的第一个字母大写
     *
     * @param str 字符串
     * @return String 处理后的字符串
     */
    public static String firstUpperCase(String str) {
        if (str == null) {
            return "";
        }

        if (str.length() == 1) {
            str = str.toUpperCase();
        } else {
            str = str.substring(0, 1).toUpperCase() + str.substring(1);
        }
        return str;
    }
}
